package com.xlhj.jpa.dao;

import com.xlhj.jpa.entity.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName SysUserDao
 * @Description 用户表持久层接口
 * @Author liucaijing
 * @Date 2021/2/24 15:40
 * @Version 1.0
 */
@Repository
public interface SysUserDao extends JpaRepository<SysUser, Long> {

    @Query("select user from sys_user user where user.userCode = ?1")
    SysUser findByUserCode(String userCode);

    @Query("select user from sys_user user where user.userName like %?1")
    List<SysUser> findByUserName(String userName);

    @Query(value = "select * from sys_user where user_name like %?1", countQuery = "select count(*) from sys_user where user_name like %?1", nativeQuery = true)
    Page<SysUser> findByUserNameAndPage(String userName, Pageable pageable);

    /*@Query(value = "SELECT * FROM USERS WHERE LASTNAME = ?1",
            countQuery = "SELECT count(*) FROM USERS WHERE LASTNAME = ?1",
            nativeQuery = true)
    Page<User> findByLastname(String lastname, Pageable pageable);*/
}
